//var oHead = document.getElementsByTagName('HEAD').item(0); 
//var oScript= document.createElement("script"); 
//oScript.type = "text/javascript"; 
//oScript.src="/scrm"+"/timePluls/jquery-form.js"; 
//oScript.src="/scrm"+"/timePluls/jquery-form.js"; 
//oHead.appendChild(oScript); 
document.write(' <script language="javascript" src="timePluls/jquery-form.js" > </script>');
/* 提示框 */
//function showDialog(title){
//	
//	$('.s_popup_delectwen,.s_consumwen').show().delay(1000).fadeOut();
//}
/*  */

/** 页面拼装 */
function customerhtml(data, html, methodName) {
	html += '<ul class="m_xabout fix J_xabout">';
	if (data.customerList == '' || data.customerList == 0) {
		html += "暂无客户";
	} else {
		$ .each( data.customerList,
						function(n, value) {
							html += '<li class="fix"> <div class="box"><div class="satell">';
							html += '<div class="tans">';
							console.log(value.newOrOldCustomer+":--------------------:::::");
							if (value.newOrOldCustomer == 2) {
								html += '<i><img src="'+path+'/images/host_6.png" /></i>';
							} else if (value.newOrOldCustomer == 3) {
								html += '<i><img src="'+path+'/images/host_3.png" /></i>';
							}
							if (value.transactionFrequency == 2) {
								html += '<i class="host"><img src="'+path+'/images/host_2.png" /></i>';
							} else if (value.transactionFrequency == 3) {
								html += '<i class="host"><img src="'+path+'/images/host_7.png" /></i>';
							} else if (value.transactionFrequency == 4) {
								html += '<i class="host"><img src="'+path+'/images/host_5.png" /></i>';
							}
							if (value.transactionLimit == 2) {
								html += '<i class="abst"><img src="'+path+'/images/host_1.png" /></i>';
							} else if (value.transactionLimit == 3) {
								html += '<i class="abst"><img src="'+path+'/images/host_8.png" /></i>';
							} else if (value.transactionLimit == 4) {
								html += '<i class="abst"><img src="'+path+'/images/host_9.png" /></i>';
							}
							html += '</div><div class="bore">';
							html += '<p><span>参与活动</span>'
									+ (value.activity_name == null ? '暂无参加活动'
											: value.activity_name) + '</p>';
							html += '<p><span>累计消费</span>'
									+ (value.money_total == null ? 0
											: value.money_total) + '</p>';
							html += '<p><span>频率/时间属性</span>'
									+ (value.totalConsumption == null ? 0
											: value.totalConsumption) + '次';
							html += '/'
									+ (value.totalDay == -1 ? "无消费记录"
											: value.totalDay) + '天</p>';
							html += '<p class="one"><span>第一次消费</span>'
									+ (value.first_write_off_time == null ? '暂无消费记录'
											: value.first_write_off_time);
							html += '<em>'
									+ (value.first_consumption_amount == null ? "/0"
											: "/"
													+ value.first_consumption_amount)
									+ '</em></p>';
							html += '<p class="one"><span>最近消费</span>'
									+ (value.lately_write_off_time == null ? '暂无消费记录'
											: value.lately_write_off_time);
							html += '<em>'
									+ (value.lately_consumption_amount == null ? "/0"
											: "/"
													+ value.lately_consumption_amount)
									+ '</em></p>';
							html += '</div>';
							html += '<div class="come">';
							html += '<p><span>来源</span>'
									+ (value.customer_source == null ? "未知"
											: value.customer_source) + '</p>';
							html += '<p><span>微博</span>' +(value.weibo == null ? '' : value.weibo)  + '</p>';
							html += '<p><span>微信</span>' + (value.wechat == null ? '' : value.wechat)
									+ '</p>';
							html += '<p><span>邮箱</span>' + (value.email == null ? '' : value.email)  + '</p>';
							html += '</div>';
							html += '<div class="nbsa">';
							if (value.newOrOldCustomer == 2) {
								html += '<b><img src="'+path+'/images/host_6.png" /></b>';
							} else if (value.newOrOldCustomer == 3) {
								html += '<b><img src="'+path+'/images/host_3.png" /></b>';
							}
							if (value.transactionFrequency == 2) {
								html += '<b><img src="'+path+'/images/host_2.png" /></b>';
							} else if (value.transactionFrequency == 3) {
								html += '<b><img src="'+path+'/images/host_7.png" /></b>';
							} else if (value.transactionFrequency == 4) {
								html += '<b><img src="'+path+'/images/host_5.png" /></b>';
							}
							if (value.transactionLimit == 2) {
								html += '<b><img src="'+path+'/images/host_1.png" /></b>';
							} else if (value.transactionLimit == 3) {
								html += '<b><img src="'+path+'/images/host_8.png" /></b>';
							} else if (value.transactionLimit == 4) {
								html += '<b><img src="'+path+'/images/host_9.png" /></b>';
							}
							html += '</div>';
							html += '<div class="pics">';
							html += '<strong><img src="'+((value.avatar == null || value.avatar == undefined || value.avatar == "") ? path+"/images/000head_pic.png" : value.avatar)+'" /></strong>';
							html += '<div class="right">';
							html += '<a href="'+path+'/api/custome/customerInfo?customerID='+(value.id == undefined ? value.customer_id : value.id)+'"'+' class="name">'+value.name+'</a>';
							html += '<div class="nvs">';
							html += '<shiro:hasPermission name="customer_info_delete_button">';
							html += '<b><img src="'+path+'/images/icon_delect.png"';
							html += 'onclick="showDelete('+(value.id == undefined ? value.customer_id : value.id)+')"/></b>';
							html += '</shiro:hasPermission>';
							html += '<shiro:hasPermission name="customer_info_update_button">';
							html += '<b><img src="'+path+'/images/icon_edit.png" ';
							html += 'onclick="findByCustomerId('+(value.id == undefined ? value.customer_id : value.id)+')"/></b>';
							html += '</shiro:hasPermission>';
							html += '<shiro:hasPermission name="customer_info_chat_button">';
							html += '<b><img src="'+path+'/images/icon_dialogue.png" onclick="dialogue('+(value.id == undefined ? value.customer_id : value.id)+')"/></b>';
							html += '</shiro:hasPermission>';
							html += '</div></div></div>';
							html += '</div></div></li>';
						});
	}
	html += '</ul>';
	html += '<div class="m_xpages">';
	html += '<div class="mian">';
	console.log("data.pageSize-------->"+data.pageSize);
	console.log("data.pageSize-------->"+data.pageSize);
	if (data.pageSize == 6) {
		html += '<span>显示行数</span> <select id="select" methodName="'
				+ methodName
				+ '"><option selected="selected">2</option><option>3</option><option >4</option></select>';
	} else if (data.pageSize == 9) {
		html += '<span>显示行数</span> <select id="select" methodName="'
				+ methodName
				+ '"><option>2</option><option selected="selected">3</option><option >4</option></select>';
	} else if (data.pageSize == 12) {
		html += '<span>显示行数</span> <select id="select" methodName="'
				+ methodName
				+ '"><option>2</option><option>3</option><option selected="selected">4</option></select>';
	}
	html += '<span>共' + data.totalCount + '条</span>';
	html += '<span>' + data.startIndex + "/" + data.pageCount + '</span> ';
	if (data.startIndex > 1) {
		html += '<a href="javascript:;" class="next" onclick="getPageListTop('
				+ "'" + methodName + "'" + ',' + (data.startIndex - 1)
				+ ')">上一页</a>';
	} else {
		html += '<a href="javascript:;" class="prev" >上一页</a>';
	}
	if (data.startIndex < data.pageCount) {
		html += '<a href="javascript:;" class="next" onclick="getPageListNext('
				+ "'" + methodName + "'" + ',' + (data.startIndex + 1)
				+ ')">下一页</a>';
	} else {
		html += '<a href="javascript:;" class="prev" >下一页</a>';
	}
	html += '<span>前往</span> <input id="tiaozhuan" currentP="'
			+ data.startIndex + '" pageCount="' + data.pageCount
			+ '" type="text" value="1" class="text" methodName="' + methodName
			+ '"><span>页</span>';
	html += '</div></div>'
	return html;
}

// 时间属性上
function totalDayTop(pagei, pageSize) {
	totalDay(pagei, pageSize, "asc", "totalDay");
}
// 时间属性下
function totalDayDown(pagei, pageSize) {
	totalDay(pagei, pageSize, "desc", "totalDay");
}
// 交易量上
function tradingVolumeTop(pagei, pageSize) {
	tradingVolume(pagei, pageSize, "asc", "tradingVolume");
}
// 交易量下
function tradingVolumeDown(pagei, pageSize) {
	tradingVolume(pagei, pageSize, "desc", "tradingVolume");
}
// 频率上
function totalConsumptionTop(pagei, pageSize) {
	totalConsumption(pagei, pageSize, "asc", "totalConsumption");
}
// 频率下
function totalConsumptionDown(pagei, pageSize) {
	totalConsumption(pagei, pageSize, "desc", "totalConsumption");
}
// 频率
function totalConsumption(pagei, pageSize, orderby, str) {
	rightTotalConsumption();
	$.post(path+'/api/custome/getTotalConsumption', {
		"nameOrphone" : $("#nameOrphone").val(),
		"activity" : activity,
		"source" : source,
		'orderby' : orderby,
		"startIndex" : pagei,
		"pagesize" : pageSize * 3,
	}, function(data) {
		data = JSON.parse(data);
		var html = "";
		var methodName = 'totalConsumption' + orderby;
		html = customerhtml(data, html, methodName);
		$(".m_xconent").html(html);
		addOrremveClass(str);
		parent.changeFrameHeight();
	});
}
// 交易量
function tradingVolume(pagei, pageSize, orderby, str) {
	customerClassification();
	$.post(path+'/api/custome/getTradingVolume', {
		"nameOrphone" : $("#nameOrphone").val(),
		"activity" : activity,
		"source" : source,
		'orderby' : orderby,
		"startIndex" : pagei,
		"pagesize" : pageSize * 3,
	}, function(data) {
		data = JSON.parse(data);
		var html = "";
		var methodName = 'tradingVolume' + orderby;
		html = customerhtml(data, html, methodName);
		$(".m_xconent").html(html);
		addOrremveClass("tradingVolume");
		parent.changeFrameHeight();
	});
}
// 时间属性
function totalDay(pagei, pageSize, orderby, str) {
	console.log("555555555555");
	rightNewOrOld();
	$.post(path+'/api/custome/getTotalDay', {
		"nameOrphone" : $("#nameOrphone").val(),
		"activity" : activity,
		"source" : source,
		'orderby' : orderby,
		"startIndex" : pagei,
		"pagesize" : pageSize * 3,
	}, function(data) {
		data = JSON.parse(data);
		var html = "";
		var methodName = 'totalDay' + orderby;
		html = customerhtml(data, html, methodName);
		$(".m_xconent").html(html);
		addOrremveClass(str);
		parent.changeFrameHeight();
	});
}
// 流失客户
function lossCustromer(pagei, pagesize) {
	getRigehtLossCustromer();
	$.post(path+'/api/custome/getLossCustromer', {
		"nameOrphone" : $("#nameOrphone").val(),
		"activity" : activity,
		"source" : source,
		"startIndex" : pagei,
		"pagesize" : pagesize * 3,
	}, function(data) {
		data = JSON.parse(data);
		var html = "";
		var methodName = "lossCustromer";
		html = customerhtml(data, html, methodName);
		addOrremveClass("lossCustromer");
		$("#totalDayTop").attr("src", path+"/images/top_1.png");
		$("#totalDayDown").attr("src", path+"/images/top_2.png");
		$("#totalConsumptionTop").attr("src", path+"/images/top_1.png");
		$("#totalConsumptionDown").attr("src", path+"/images/top_2.png");
		$("#tradingVolumeTop").attr("src", path+"/images/top_1.png");
		$("#tradingVolumeDown").attr("src", path+"/images/top_2.png");
		$(".m_xconent").html(html);
		parent.changeFrameHeight();
	});
}
// 查询按钮事件
function searchCustmerList() {
	customerList(startIndex, pageSize);
}
// 获取来源下拉框数据
function getSourceList() {
	$.post(path+'/api/customeSource/getCustomerSourceList', {},
			function(data) {
				var html = '<li onclick="selectSource(' + "'全部'"
						+ ',0)">全部</li>';
				data = JSON.parse(data);
				$.each(data.customerSourceList, function(n, value) {
					html += '<li value="' + value.id
							+ '" onclick="selectSource(' + "'" + value.name
							+ "'" + ',' + value.id + ')">' + value.name
							+ '</li>'
				});
				$("#source").append(html);
			});

}
// 查询条件来源下拉框赋值
function selectSource(name, id) {
	$("#allsource").html(name);
	if (id == 0) {
		source = '';
	} else {
		source = id;
	}
}
// 查询条件来源下拉框赋值
function selectActivity(state) {
	if (state == 1) {
		$("#selectActivity").html("已参加");
		activity = state;
	} else if (state == 2) {
		$("#selectActivity").html("未参加");
		activity = state;
	} else {
		$("#selectActivity").html("全部");
		activity = '';
	}

}
// 更改样式方法
function addOrremveClass(str) {
	$("#customerList").removeClass("blue");
	$("#totalDay").removeClass("blue");
	$("#totalConsumption").removeClass("blue");
	$("#tradingVolume").removeClass("blue");
	$("#lossCustromer").removeClass("blue");
	$("#" + str + "").addClass("blue");
}
// 右侧分类列表数据  主力
function customerClassification() {
	$.post(path+'/api/custome/getCustomerClassification', {},
			function(data) {
				var html = '';
				data = JSON.parse(data);
				html = customerClassificationHtml(data, html);
				$(".m_xmeans").html(html);
			});
}
//右侧分类新老客户
function rightNewOrOld() {
	$.post(path+'/api/custome/rightNewOrOld', {},
			function(data) {
				var html = '';
				data = JSON.parse(data);
				html = rightNewOrOldHtml(data,html);
				$(".m_xmeans").html(html);
			});
}

//右侧分类交易频率  常客
function rightTotalConsumption() {
	$.post(path+'/api/custome/rightTotalConsumption', {},
			function(data) {
				var html = '';
				data = JSON.parse(data);
				html = rightTotalConsumptionHtml(data,html);
				$(".m_xmeans").html(html);
			});
}
//右侧分类交易频率  常客
function getRigehtLossCustromer() {
	$.post(path+'/api/custome/getRigehtLossCustromer', {},
			function(data) {
				var html = '';
				data = JSON.parse(data);
				html = getRigehtLossCustromerHtml(data,html);
				$(".m_xmeans").html(html);
			});
}
function getRigehtLossCustromerHtml(data, html) {
	html += '<p class="J_xtabs" style="color: #03a9f4;text-align:center;height:50px;line-height: 50px;">';
	html += '<span style="vertical-align:middle;">流失客户</span>';
	/*html += '<a href="javascript:;" class="on" style="">流失客户</a> ';*/
	html += '</p>'
	html += '<div class="m_xchoose J_xchoose">';
	html += '<div class="m_wxcon_tb on">';
	html += '<div class="tabs">';
	html += '<span style="width: 27%;"><em>姓名</em></span> <span style="width: 38%;">电话</span> <span style="width: 35%;">消费间隔</span>';
	html += '</div>';
	html += '<ul>';
	if (data.lossCustromer == '0') {
		html += '<li>' + "请设置流失维度属性" + '</li>';
	} else if (data.lossCustromer == '' || data.lossCustromer == null) {
		html += '<li>' + "暂流失客户" + '</li>';
	} else {
		$.each(data.lossCustromer, function(n, value) {
			html += '<li><a href="javascript:;" title="'+ (value.name == undefined ? '暂无' : value.name) +'" class="name on" style="width:23%; white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">'
					+ (value.name == undefined || value.name == null || value.name == "" ? '暂无' : value.name) + '</a>';
			html += '<span>' + (value.phone == undefined || value.phone == null || value.phone == "" ? '未知' : value.phone)
					+ '</span>';
			html += '<em><img src="'+path+'/images/icon_dialogue.png" onclick="dialogue('+(value.customer_id )+')"  />';
			html += (value.tday == undefined ? '0' : value.tday) + '天</em></li>';
		});
	}
	html += '</ul>';
	html += '</div>';
	html += '</div>';
	return html;
}


//拼装客户分类列表
function rightTotalConsumptionHtml(data, html) {
	html += '<p class="J_xtabs">';
	html += '<a href="javascript:;" class="on">过客</a> <a href="javascript:;">常客</a> <a href="javascript:;">忠实客户</a>';
	html += '</p>'
	html += '<div class="m_xchoose J_xchoose">';
	html += '<div class="m_wxcon_tb on">';
	html += '<div class="tabs">';
	html += '<span style="width: 27%;"><em>姓名</em></span> <span style="width: 38%;">电话</span> <span style="width: 35%;">累计(天/次）</span>';
	html += '</div>';
	html += '<ul>';
	console.log("--------11111111112222222222------->");
	console.log("----->"+data.traveler);
	console.log("----->"+data.regular);
	console.log("----->"+data.loyalCustomer);
	if (data.traveler == '0') {
		html += '<li>' + "请设置过客维度属性" + '</li>';
	} else if (data.traveler == '' || data.traveler == null) {
		html += '<li>' + "暂无过客" + '</li>';
	} else {
		$.each(data.traveler, function(n, value) {
			html += '<li><a href="javascript:;" title="'+ (value.name == undefined ? '暂无' : value.name) +'" class="name on" style="width:23%; white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">'
					+ (value.name == undefined ? '暂无' : value.name) + '</a>';
			html += '<span>' + (value.phone == undefined ? '未知' : value.phone)
					+ '</span>';
			html += '<em><img src="'+path+'/images/icon_dialogue.png" onclick="dialogue('+(value.customer_id )+')" />';
			html += (value.daya == undefined ? '0' : value.daya) + '/'
					+ (value.customerCount == undefined ? '0' : value.customerCount)
					+ '</em></li>';
		});
	}
	html += '</ul>';
	html += '</div>';
	html += '<div class="m_wxcon_tb">';
	html += '<div class="tabs">';
	html += '<span style="width: 27%;"><em>姓名</em></span> <span style="width: 38%;">电话</span> <span style="width: 35%;">累计(天/次）</span>';
	html += '</div>';
	html += '<ul>';
	if (data.regular == '0') {
		html += '<li>' + "请设置常客维度属性" + '</li>';
	} else if (data.regular == '' || data.regular == null) {
		html += '<li>' + "暂无常客" + '</li>';
	} else {
		$.each(data.regular, function(n, value) {
			html += '<li><a href="javascript:;" title="'+ (value.name == undefined ? '暂无' : value.name) +'" class="name on" style="width:23%; white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">'
					+ (value.name == undefined ? '暂无' : value.name) + '</a>';
			html += '<span>' + (value.phone == undefined ? '未知' : value.phone)
					+ '</span>';
			html += '<em><img src="'+path+'/images/icon_dialogue.png" onclick="dialogue('+(value.customer_id )+')"  />';
			html += (value.daya == undefined ? '0' : value.daya) + '/'
					+ (value.customerCount == undefined ? '0' : value.customerCount)
					+ '</em></li>';
		});
	}
	html += '</ul>';
	html += '</div>';
	html += '<div class="m_wxcon_tb">';
	html += '<div class="tabs">';
	html += '<span style="width: 27%;"><em>姓名</em></span> <span style="width: 38%;">电话</span> <span style="width: 35%;">累计(天/次）</span>';
	html += '</div>';
	html += '<ul>';
	if (data.loyalCustomer == '0') {
		html += '<li>' + "请设置忠客维度属性" + '</li>';
	} else if (data.loyalCustomer == '' || data.loyalCustomer == null) {
		html += '<li>' + "暂无忠客" + '</li>';
	} else {
		$.each(data.loyalCustomer, function(n, value) {
			html += '<li><a href="javascript:;" title="'+ (value.name == undefined ? '暂无' : value.name) +'" class="name on" style="width:23%; white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">'
					+ (value.name == undefined ? '暂无' : value.name) + '</a>';
			html += '<span>' + (value.phone == undefined ? '未知' : value.phone)
					+ '</span>';
			html += '<em><img src="'+path+'/images/icon_dialogue.png"  onclick="dialogue('+(value.customer_id )+')" />';
			html += (value.daya == undefined ? '0' : value.daya) + '/'
					+ (value.customerCount == undefined ? '0' : value.customerCount)
					+ '</em></li>';
		});
	}
	html += '</ul>';
	html += '</div>';
	html += '</div>';
	return html;
}
//拼装客户分类列表
function rightNewOrOldHtml(data, html) {
	html += '<p class="J_xtabs">';
	html += '<a href="javascript:;" class="on">新客户</a> <a href="javascript:;">老客户</a>';
	html += '</p>'
	html += '<div class="m_xchoose J_xchoose">';
	html += '<div class="m_wxcon_tb on">';
	html += '<div class="tabs">';
	html += '<span style="width: 27%;"><em>姓名</em></span> <span style="width: 38%;">电话</span> <span style="width: 35%;">累计(天/次）</span>';
	html += '</div>';
	html += '<ul>';
	if (data.newCustomer == '0') {
		html += '<li>' + "请设置新客户维度属性" + '</li>';
	} else if (data.newCustomer == '' || data.newCustomer == null) {
		html += '<li>' + "暂无新客户" + '</li>';
	} else {
		$.each(data.newCustomer, function(n, value) {
			html += '<li><a href="javascript:;" title="'+ (value.cusName == undefined ? '暂无' : value.cusName) +'" class="name on" style="width:23%; white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">'
					+ (value.cusName == undefined ? '暂无' : value.cusName) + '</a>';
			html += '<span>' + (value.cusPhone == undefined ? '未知' : value.cusPhone)
					+ '</span>';
			html += '<em><img src="'+path+'/images/icon_dialogue.png" onclick="dialogue('+(value.cusId )+')"  />';
			html += (value.daya == undefined ? '0' : value.daya) + '/'
					+ (value.buyTimes == undefined ? '0' : value.buyTimes)
					+ '</em></li>';
		});
	}
	html += '</ul>';
	html += '</div>';
	html += '<div class="m_wxcon_tb">';
	html += '<div class="tabs">';
	html += '<span style="width: 27%;"><em>姓名</em></span> <span style="width: 38%;">电话</span> <span style="width: 35%;">累计(天/次）</span>';
	html += '</div>';
	html += '<ul>';
	if (data.oldCustomer == '0') {
		html += '<li>' + "请设置老客户维度属性" + '</li>';
	} else if (data.oldCustomer == '' || data.oldCustomer == null) {
		html += '<li>' + "暂无老客户" + '</li>';
	} else {
		$.each(data.oldCustomer, function(n, value) {
			html += '<li><a href="javascript:;" title="'+ (value.cusName == undefined ? '暂无' : value.cusName) +'" class="name on" style="width:23%; white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">'
					+ (value.cusName == undefined ? '暂无' : value.cusName) + '</a>';
			html += '<span>' + (value.cusPhone == undefined ? '未知' : value.cusPhone)
					+ '</span>';
			html += '<em><img src="'+path+'/images/icon_dialogue.png"  onclick="dialogue('+(value.cusId )+')"/>';
			html += (value.daya == undefined ? '0' : value.daya) + '/'
					+ (value.buyTimes == undefined ? '0' : value.buyTimes)
					+ '</em></li>';
		});
	}
	html += '</ul>';
	html += '</div>';
	html += '</div>';
	return html;
}


// 拼装客户分类列表
function customerClassificationHtml(data, html) {
	html += '<p class="J_xtabs">';
	html += '<a href="javascript:;" class="on">主力客户</a> <a href="javascript:;">一般客户</a>';
	html += '<a href="javascript:;">零散客户</a></p>'
	html += '<div class="m_xchoose J_xchoose">';
	html += '<div class="m_wxcon_tb on">';
	html += '<div class="tabs">';
	html += '<span style="width: 27%;"><em>姓名</em></span> <span style="width: 38%;">电话</span> <span style="width: 35%;">累计消费(元)</span>';
	html += '</div>';
	html += '<ul>';
	if (data.mainForceList[0] == '0') {
		html += '<li>' + "请设置主力客户维度属性" + '</li>';
	} else if (data.mainForceList == '' || data.mainForceList == null) {
		html += '<li>' + "暂无主力客户" + '</li>';
	} else {
		$.each(data.mainForceList, function(n, value) {
			html += '<li><a href="javascript:;" title="'+ (value.cusName == undefined ? '暂无' : value.cusName) +'" class="name on" style="width:23%; white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">'
					+ (value.cusName == undefined ? '暂无' : value.cusName) + '</a>';
			html += '<span>' + (value.cusPhone == undefined ? '未知' : value.cusPhone)
					+ '</span>';
			html += '<em><img src="'+path+'/images/icon_dialogue.png" onclick="dialogue('+(value.cusId )+')"/>';
			html += (value.amount == undefined ? '0' : value.amount) +  '</em></li>';
		});
	}
	html += '</ul>';
	html += '</div>';
	html += '<div class="m_wxcon_tb">';
	html += '<div class="tabs">';
	html += '<span style="width: 27%;"><em>姓名</em></span> <span style="width: 38%;">电话</span> <span style="width: 35%;">累计消费(元)</span>';
	html += '</div>';
	html += '<ul>';
	if (data.commonlyList[0] == '0') {
		html += '<li>' + "请设置一般客户维度属性" + '</li>';
	} else if (data.commonlyList == '' || data.commonlyList == null) {
		html += '<li>' + "暂无一般客户" + '</li>';
	} else {
		$.each(data.commonlyList, function(n, value) {
			html += '<li><a href="javascript:;" title="'+ (value.cusName == undefined ? '暂无' : value.cusName) +'" class="name on" style="width:23%; white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">'
					+ (value.cusName == undefined ? '暂无' : value.cusName) + '</a>';
			html += '<span>' + (value.cusPhone == undefined ? '未知' : value.cusPhone)
					+ '</span>';
			html += '<em><img src="'+path+'/images/icon_dialogue.png" onclick="dialogue('+(value.cusId )+')"/>';
			html += (value.amount == undefined ? '0' : value.amount) +  '</em></li>';
		});
	}
	html += '</ul>';
	html += '</div>';
	html += '<div class="m_wxcon_tb">';
	html += '<div class="tabs">';
	html += '<span style="width: 27%;"><em>姓名</em></span> <span style="width: 38%;">电话</span> <span style="width: 35%;">累计消费(元)</span>';
	html += '</div>';
	html += '<ul>';
	if (data.scatteredList[0] == '0') {
		html += '<li>' + "请设置零散客户维度属性" + '</li>';
	} else if (data.scatteredList == '' || data.scatteredList == null) {
		html += '<li>' + "暂无零散客户" + '</li>';
	} else {
		$.each(data.scatteredList, function(n, value) {
			html += '<li><a href="javascript:;" title="'+ (value.cusName == undefined ? '暂无' : value.cusName) +'" class="name on" style="width:23%; white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">'
					+ (value.cusName == undefined ? '暂无' : value.cusName) + '</a>';
			html += '<span>' + (value.cusPhone == undefined ? '未知' : value.cusPhone)
					+ '</span>';
			html += '<em><img src="'+path+'/images/icon_dialogue.png" onclick="dialogue('+(value.cusId )+')" />';
			html += (value.amount == undefined ? '0' : value.amount) +  '</em></li>';
		});
	}
	html += '</ul>';
	html += '</div>';
	html += '</div>';
	return html;
}
//获取全部用户资料
function customerList(pagei,pagesize){
	$.post(path+'/api/custome/customerDetailList', {
    		"nameOrphone":$("#nameOrphone").val(),
			"activity" : activity,
			"source" : source,
			"startIndex" : pagei,
			"pagesize" : pagesize * 3,
		}, function(data) {
			data = JSON.parse(data);
			var html = "";
			var methodName = 'customerList';
			html = customerhtml(data,html,methodName);
			$(".m_xconent").html(html);
			parent.changeFrameHeight();
		});
	}
//上一页
function getPageListTop(methodName,pagei){
	var pages = $("#select").val()
	if(methodName == 'customerList'){
		customerList(pagei,pages);
	}else if(methodName == 'lossCustromer'){
		lossCustromer(pagei,pages);
	}else if(methodName == 'totalDaydesc'){
		console.log("1111111111111111111111");
		totalDayDown(pagei,pages);
	}else if(methodName == 'totalDayasc'){
		console.log("222222222222222222222");
		totalDayTop(pagei,pages);
		
	}else if(methodName == 'tradingVolumeasc'){
		tradingVolumeTop(pagei,pages);
	}else if(methodName == 'tradingVolumedesc'){
		tradingVolumeDown(pagei,pages);
	}else if(methodName == 'totalConsumptionasc'){
		totalConsumptionDown(pagei,pages);
	}else if(methodName == 'totalConsumptiondesc'){
		totalConsumptionTop(pagei,pages);
	}
}
//下一页
function getPageListNext(methodName,pagei){
	console.log("66666666666666---------->"+methodName+"----->"+pagei);
	var pages = $("#select").val()
	if(methodName == 'customerList'){
		customerList(pagei,pages);
	}else if(methodName == 'lossCustromer'){
		lossCustromer(pagei,pages);
	}else if(methodName == 'totalDaydesc'){
		console.log("77777777777777");
		totalDayDown(pagei,pages);
	}else if(methodName == 'totalDayasc'){
		console.log("8888888888888888");
		totalDayTop(pagei,pages);
	
	}else if(methodName == 'tradingVolumeasc'){
		tradingVolumeTop(pagei,pages);
	}else if(methodName == 'tradingVolumedesc'){
		tradingVolumeDown(pagei,pages);
	}else if(methodName == 'totalConsumptionasc'){
		totalConsumptionDown(pagei,pages);
	}else if(methodName == 'totalConsumptiondesc'){
		totalConsumptionTop(pagei,pages);
	}
	
}

function saveOrUpdate(){
	var cID = $("#customerID").val();
	var myregPhone  = /^(0|86|17951)?(13[0-9]|15[012356789]|17[0135678]|18[0-9]|14[579])[0-9]{8}$/; 
	var myregEmail = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
	if($("#phonea").val() == '' || $("#phonea").val() == null){
		alert('手机号码不能为空！'); 
	    return false; 
	}else{
		if(!myregPhone.test($("#phonea").val()))  { 
		    alert('请输入有效的手机号码！'); 
		    return false; 
		}
	}
	if( $("#emaila").val() == '' || $("#emaila").val() == null){
		
	}else{
		if(!myregEmail.test($("#emaila").val()))  { 
		    alert('请输入正确的邮箱！'); 
		    return false; 
		}
	}
	if(cID != ''){
		editCustomer(cID);
		//editCustomerExtend(cID);//编辑扩展信息
		customerList(1,pageSize);
	}else{
		saveCustomer();
//		saveCustomerExtend();//存储扩展信息（id从saveCustomer()接口中拿）
		customerList(1,pageSize);
	}
}

//编辑或存储扩展信息
var finaldata = "";//封装数据
var extendstatus = 0;
//存储扩展信息（id从saveCustomer()接口中拿）
function saveCustomerExtend(){
	console.log("进入扩展放啊");
	//遍历扩展内容
	//var datastringlist = "";
	var dataid = "";//获取键
	var datatype = "";//获取类型
	var dataval = "";//获取值
	
	finaldata = "";//清空原数据
	extendstatus=1;
	$('#fix_html>div>.datatime').each(function(m,data) {
		extendstatus=0;
		
	if (($(data).text())!=null&&($(data).text())!="") {
		
		
		dataid =$(data).text().trim();
		console.log("获取名字："+dataid);
		datatype = $("#TypeId"+dataid).text().trim();
		console.log("获取类型："+datatype);
		if (datatype=="数字"||datatype=="单行文本"||datatype=="多行文本"||datatype=="日期"||datatype=="评分") {
			dataval  = $("#fix_"+dataid).val();
			console.log("val:"+dataval);
		}
		if (datatype=="单选"||datatype=="下拉列表") {
			dataval  = $("#fix_"+dataid).find('option:selected').text();
			console.log("sel:"+dataval);
		}
		if (datatype=="多选") {
			$("#fix_"+dataid).find('option:selected').each(function() {
				dataval+=$(this).attr("value")+"&";
			});
			console.log("sels:"+dataval);
		}
		if (datatype=="图片"||datatype=="附件") {
			//获取路径
		    var 	urlpath = "";
			if (($('#SavePathForjS').text().trim())!=null&&$('#SavePathForjS').text().trim()!="") {
				urlpath=	$('#SavePathForjS').text().trim();
			} else {
				urlpath=path;
			}
			
			var filename  = "fix_"+dataid;
					if (datatype=="图片") {
								 //提交表单
								var fileid = "#file_"+dataid;
								console.log(fileid);
								 $(fileid).submit(function () {  
									 console.log(filename);
							          $(fileid).ajaxSubmit({
							              type: "post",
							              async: false,
							              crossDomain: true,
							              url: urlpath+"/api/uploadfile/file",
							              data:{"typename":filename},
							              success: function (data) {
							            	 
							            	  if (data.message!=null) {
												console.log(data.message);
												dataval = data.realSavePath;
												console.log(dataval);
											  }
							              }
							          });
							          return false;
							      });
							      $(fileid).submit();
						
						console.log("图片路径输出:"+dataval);
					}
					if (datatype=="附件") {
						//获取路径
						var 	urlpath = "";
						if (($('#SavePathForjS').text().trim())!=null&&$('#SavePathForjS').text().trim()!="") {
							urlpath=	$('#SavePathForjS').text().trim();
						} else {
							urlpath=path;
						}
						
								 //提交表单
								var fileid = "#realfile_"+dataid;
								
								var file_name = $('#'+filename).val();
								console.log("上传的文件名"+file_name);
								var ar = new Array();
								ar = file_name.split(".");
								if ((ar[1])=="png"||(ar[1])=="PNG"||(ar[1])=="GIF"||(ar[1])=="gif"||(ar[1])=="JPG"
									||(ar[1])=="jpg"||(ar[1])=="mp3"||(ar[1])=="mp4"||(ar[1])=="MP3"||(ar[1])=="MP4") {
									alert("上传附件仅支持文档格式,此项不予生成");
									//showDialog("上传附件仅支持文档格式,此项不予生成");
								} else {
									console.log(fileid);
									 $(fileid).submit(function () {  
										 console.log(filename);
								          $(fileid).ajaxSubmit({
								              type: "post",
								              async: false,
								              crossDomain: true,
								              url: urlpath+"/api/uploadfile/file",
								              data:{"typename":filename,"isFile":true},
								              success: function (data) {
								            	 
								            	  if (data.message!=null) {
													console.log(data.message);
													dataval = data.realSavePath;
													console.log(dataval);
												  }
								              }
								          });
								          return false;
								      });
								      $(fileid).submit();
								}
								
								
						console.log("文件路径输出:"+dataval);
					}
			
				}
				if (datatype=="分割线") {
					dataval  = dataid;
					console.log("分割线:"+dataval);
				}
				
					   
							   if (dataval!=null&&dataval!="") {
									//去除重复数据
								    var statusff = 0;
									if (finaldata!=""&&finaldata!=null) {
										if (datatype!="分割线") {
											var compare = "type :"+"\""+datatype+"\""+","+"key :"+"\""+dataid+"\"";
											 //进行比对
											console.log("compare="+compare);
											 var strs = finaldata;
											
												 if(finaldata.indexOf(compare)>-1) {
												  statusff=1;
												  alert("发现存在重复数据，只对第一组数据进行添加!!");
												 } 
											
											
										}
									}
									if (statusff==1) {
										finaldata+="";
									} else {
										//封装遍历数据到json参数
										finaldata += "{type :"+"\""+datatype+"\""+","+"key :"+"\""+dataid+"\""+","+"value :"+"\""+dataval+"\""+"}"+","; 
										extendstatus=1;//成功状态
									}
									
							
							} else {
								console.log(extendstatus+"数据存在空值或者存在重名自定义控件，请重新定义");
								
						      //alert("数据存在空值或者存在重名自定义控件，请重新定义");
							}
			
		
			} else {
				extendstatus=1;//空值判断
			}
		
	});
	

	
}

//修改客户资料
function editCustomer(cID){
	
	//调用扩展方法
	saveCustomerExtend();
	console.log("集合串:"+finaldata);
	if (extendstatus==1) {//判断扩展信息是否正确传递过来
		extendstatus = 0;
		$.post(path+'/api/custome/editCustomer', {
			"customerID" : cID,
			"name" : $("#namea").val(),
			"phone" : $("#phonea").val(),
			"email" : $("#emaila").val(),
			"company" : $("#companya").val(),
			"job" : $("#joba").val(),
			"remarks" : $("#remarksa").val(),
			"gender" : $("#gendera").val(),
			"birthday" : $("#birthdaya").val(),
			"weibo" : $("#weiboa").val(),
			"qq" : $("#qqa").val(),
			"wechat" : $("#wechata").val(),
			"city" : $("#citya").val(),
			"fax" : $("#faxa").val(),
			"tag" : $("#taga").val(),
			"address" : $("#addressa").val(),
			"extenddata":finaldata,
		}, function(data) {
			$('.m_xpopups').removeClass('show');
			alert(data.error_msg);
		});
	
	} else {
       alert("您的自定义内容存在错误,数据存在空值或者存在重名自定义控件,请重新自定义");
	}
	
}
//保存客户资料
function saveCustomer(){
	//调用扩展方法
	saveCustomerExtend();
	console.log("集合串:"+finaldata);
	if (extendstatus==1) {//判断扩展信息是否正确传递过来
		extendstatus = 0;
			$.post(path+'/api/custome/addCustomer', {
				"name" : $("#namea").val(),
				"phone" : $("#phonea").val(),
				"email" : $("#emaila").val(),
				"company" : $("#companya").val(),
				"job" : $("#joba").val(),
				"remarks" : $("#remarksa").val(),
				"gender" : $("#gendera").val(),
				"birthday" : $("#birthdaya").val(),
				"weibo" : $("#weiboa").val(),
				"qq" : $("#qqa").val(),
				"wechat" : $("#wechata").val(),
				"city" : $("#citya").val(),
				"fax" : $("#faxa").val(),
				"tag" : $("#taga").val(),
				"address" : $("#addressa").val(),
				"extenddata":finaldata,
			}, function(data) {
				$('.m_xpopups').removeClass('show');
				alert(data.error_msg);
			});

	    } else {
	       alert("您的自定义内容存在错误,数据存在空值或者存在重名自定义控件,请重新自定义");
		}
}
function ifDimension(){
	var isDimension = true;
	var traveler = parseFloat($("#traveler_frequency").val()) / parseFloat($("#traveler_day").val());
	var regular = parseFloat($("#regular_frequency").val()) / parseFloat($("#regular_day").val());
	var loyal_customer =  parseFloat($("#loyal_customer_frequency").val()) / parseFloat($("#loyal_customer_day").val());
	var main_force = parseInt($("#main_force").val());
	var s_commonly_customer = parseInt($("#s_commonly_customer").val());
	var b_commonly_customer = parseInt($("#b_commonly_customer").val());
	var scattered_customer = parseInt($("#scattered_customer").val());
	if(main_force != null && b_commonly_customer != null){
		if(main_force < b_commonly_customer){
			alert("维度属性设置错误,主力客户消费金额要大于普通客户最大值！");
			isDimension =  false;
		}
	}
	if(s_commonly_customer != null && b_commonly_customer != null){
		if(b_commonly_customer < s_commonly_customer){
			alert("维度属性设置错误,普通客户消费金额最大值要大于最小值！");
			isDimension =  false;
		}
	}
	if(s_commonly_customer != null && scattered_customer != null){
		if(s_commonly_customer < scattered_customer){
			alert("维度属性设置错误,散客消费金额要小于普通客户最小值！");
			isDimension =  false;
		}
	}
	if(traveler != 0 && regular != 0){
		if(traveler > regular){
			alert("维度属性设置错误,常客交易频率要大于过客交易频率！");
			isDimension =  false;
		}
	}
	if(regular != 0 && loyal_customer != 0){
		if(regular > loyal_customer){
			alert("维度属性设置错误,常客交易频率要小于忠客交易频率！");
			isDimension =  false;
		}
	}
	return isDimension;
}
//添加用户维度
function saveUserDimension(){
	if(ifDimension()){
		$.post(path+'/api/userDimension/addUserDimension', {
			"old_customer_day" : $("#old_customer_day").val(),
			"old_customer_frequency" : $("#old_customer_frequency").val(),
			"new_customer_day" : $("#new_customer_day").val(),
			"new_customer_frequency" : $("#new_customer_frequency").val(),
			"traveler_day" : $("#traveler_day").val(),
			"traveler_frequency" : $("#traveler_frequency").val(),
			"regular_day" : $("#regular_day").val(),
			"regular_frequency" : $("#regular_frequency").val(),
			"loyal_customer_day" : $("#loyal_customer_day").val(),
			"loyal_customer_frequency" : $("#loyal_customer_frequency").val(),
			"main_force" : $("#main_force").val(),
			"s_commonly_customer" : $("#s_commonly_customer").val(),
			"b_commonly_customer" : $("#b_commonly_customer").val(),
			"scattered_customer" : $("#scattered_customer").val(),
			"lose_customer" : $("#lose_customer").val(),
		}, function(data) {
			if(data.error_code == 0){
				alert("操作成功！！！");
			}else{
				alert("操作失败！！！");
			}
		});
	}else{
		alert("请重新设置！");
	}
}

$(function(){
	//流失客户
	$("#lossCustromer").click(function() {
		lossCustromer(1,pageSize,nameOrphone,activity,source);
	});
	//全部
	$("#customerList").click(function() {
		customerList(1,pageSize);
		addOrremveClass("customerList");
		$("#totalDayTop").attr("src",path+"/images/top_1.png");
		$("#totalDayDown").attr("src",path+"/images/top_2.png");
		$("#totalConsumptionTop").attr("src",path+"/images/top_1.png");
		$("#totalConsumptionDown").attr("src",path+"/images/top_2.png");
		$("#tradingVolumeTop").attr("src",path+"/images/top_1.png");
		$("#tradingVolumeDown").attr("src",path+"/images/top_2.png");
//			$(".m_xconent").html(html);
	});
	$("#totalDay").click(function(){
		if(totalDayNum == 0) {
			totalDayNum = 1;
			$("#totalDayTop").attr("src",path+"/images/top_3.png");
			$("#totalDayDown").attr("src",path+"/images/top_2.png");
			$("#totalConsumptionTop").attr("src",path+"/images/top_1.png");
			$("#totalConsumptionDown").attr("src",path+"/images/top_2.png");
			$("#tradingVolumeTop").attr("src",path+"/images/top_1.png");
			$("#tradingVolumeDown").attr("src",path+"/images/top_2.png");
			totalDayTop(1,pageSize);
		}else{
			totalDayNum = 0;
			$("#totalDayTop").attr("src",path+"/images/top_1.png");
			$("#totalDayDown").attr("src",path+"/images/top_4.png");
			$("#totalConsumptionTop").attr("src",path+"/images/top_1.png");
			$("#totalConsumptionDown").attr("src",path+"/images/top_2.png");
			$("#tradingVolumeTop").attr("src",path+"/images/top_1.png");
			$("#tradingVolumeDown").attr("src",path+"/images/top_2.png");
			totalDayDown(1,pageSize);
		}
	});
	
	//时间属性上
	$("#totalDayTop").click(function() {
		$("#totalDayTop").attr("src",path+"/images/top_3.png");
		$("#totalDayDown").attr("src",path+"/images/top_2.png");
		$("#totalConsumptionTop").attr("src",path+"/images/top_1.png");
		$("#totalConsumptionDown").attr("src",path+"/images/top_2.png");
		$("#tradingVolumeTop").attr("src",path+"/images/top_1.png");
		$("#tradingVolumeDown").attr("src",path+"/images/top_2.png");
		totalDayTop(1,pageSize);
	});
	
	//时间属性下
	$("#totalDayDown").click(function() {
		$("#totalDayTop").attr("src",path+"/images/top_1.png");
		$("#totalDayDown").attr("src",path+"/images/top_4.png");
		$("#totalConsumptionTop").attr("src",path+"/images/top_1.png");
		$("#totalConsumptionDown").attr("src",path+"/images/top_2.png");
		$("#tradingVolumeTop").attr("src",path+"/images/top_1.png");
		$("#tradingVolumeDown").attr("src",path+"/images/top_2.png");
		totalDayDown(1,pageSize);
	});
	
	$("#totalConsumption").click(function(){
		if(totalConsumptionNum == 0){
			$("#totalDayTop").attr("src",path+"/images/top_1.png");
			$("#totalDayDown").attr("src",path+"/images/top_2.png");
			$("#totalConsumptionTop").attr("src",path+"/images/top_3.png");
			$("#totalConsumptionDown").attr("src",path+"/images/top_2.png");
			$("#tradingVolumeTop").attr("src",path+"/images/top_1.png");
			$("#tradingVolumeDown").attr("src",path+"/images/top_2.png");
			totalConsumptionNum = 1;
			totalConsumptionTop(1,pageSize);
		}else{
			$("#totalDayTop").attr("src",path+"/images/top_1.png");
			$("#totalDayDown").attr("src",path+"/images/top_2.png");
			$("#totalConsumptionTop").attr("src",path+"/images/top_1.png");
			$("#totalConsumptionDown").attr("src",path+"/images/top_4.png");
			$("#tradingVolumeTop").attr("src",path+"/images/top_1.png");
			$("#tradingVolumeDown").attr("src",path+"/images/top_2.png");
			totalConsumptionNum = 0;
			totalConsumptionDown(1,pageSize);
		}
	});
	$("#tradingVolume").click(function(){
		if(tradingVolumeNum == 0){
			$("#totalDayTop").attr("src",path+"/images/top_1.png");
			$("#totalDayDown").attr("src",path+"/images/top_2.png");
			$("#totalConsumptionTop").attr("src",path+"/images/top_1.png");
			$("#totalConsumptionDown").attr("src",path+"/images/top_2.png");
			$("#tradingVolumeTop").attr("src",path+"/images/top_3.png");
			$("#tradingVolumeDown").attr("src",path+"/images/top_2.png");
			tradingVolumeNum= 1;
			tradingVolumeTop(1,pageSize);
		}else{
			$("#totalDayTop").attr("src",path+"/images/top_1.png");
			$("#totalDayDown").attr("src",path+"/images/top_2.png");
			$("#totalConsumptionTop").attr("src",path+"/images/top_1.png");
			$("#totalConsumptionDown").attr("src",path+"/images/top_2.png");
			$("#tradingVolumeTop").attr("src",path+"/images/top_1.png");
			$("#tradingVolumeDown").attr("src",path+"/images/top_4.png");
			tradingVolumeNum = 0;
			tradingVolumeDown(1,pageSize);
		}
	});
	//交易量上
	$("#tradingVolumeTop").click(function() {
		$("#totalDayTop").attr("src",path+"/images/top_1.png");
		$("#totalDayDown").attr("src",path+"/images/top_2.png");
		$("#totalConsumptionTop").attr("src",path+"/images/top_1.png");
		$("#totalConsumptionDown").attr("src",path+"/images/top_2.png");
		$("#tradingVolumeTop").attr("src",path+"/images/top_3.png");
		$("#tradingVolumeDown").attr("src",path+"/images/top_2.png");
		tradingVolume(1,pageSize);
	});
	//交易量下
	$("#tradingVolumeDown").click(function() {
		$("#totalDayTop").attr("src",path+"/images/top_1.png");
		$("#totalDayDown").attr("src",path+"/images/top_2.png");
		$("#totalConsumptionTop").attr("src",path+"/images/top_1.png");
		$("#totalConsumptionDown").attr("src",path+"/images/top_2.png");
		$("#tradingVolumeTop").attr("src",path+"/images/top_1.png");
		$("#tradingVolumeDown").attr("src",path+"/images/top_4.png");
		tradingVolumeDown(1,pageSize);
	});
	
	//频率上
	$("#totalConsumptionTop").click(function() {
		$("#totalDayTop").attr("src",path+"/images/top_1.png");
		$("#totalDayDown").attr("src",path+"/images/top_2.png");
		$("#totalConsumptionTop").attr("src",path+"/images/top_1.png");
		$("#totalConsumptionDown").attr("src",path+"/images/top_4.png");
		$("#tradingVolumeTop").attr("src",path+"/images/top_1.png");
		$("#tradingVolumeDown").attr("src",path+"/images/top_2.png");
		totalConsumptionTop(1,pageSize);
	});
	
	//频率下
	$("#totalConsumptionDown").click(function() {
		$("#totalDayTop").attr("src",path+"/images/top_1.png");
		$("#totalDayDown").attr("src",path+"/images/top_2.png");
		$("#totalConsumptionTop").attr("src",path+"/images/top_1.png");
		$("#totalConsumptionDown").attr("src",path+"/images/top_4.png");
		$("#tradingVolumeTop").attr("src",path+"/images/top_1.png");
		$("#tradingVolumeDown").attr("src",path+"/images/top_2.png");
		totalConsumptionDown(1,pageSize);
	});
	
});

function showDelete(id){
	$('.s_popup_box').addClass("show");
	$('.s_popup_detailed').addClass("show");
	$('.s_popup_box').removeClass("hide");
	$('.s_popup_detailed').removeClass("hide");
	$('#save_del_id').text(id);
}
function s_confirm_del(){
	
	var id= $('#save_del_id').text().trim();
	
	  if(true) { 
		  $.post(path+'/api/custome/delectCustomer', {
				"id" : id,
			}, function(data) {
				data = JSON.parse(data);
				if(data.success == 1){
					customerList(1,pageSize);
					
					$('.s_popup_box').addClass("hide");
					$('.s_popup_detailed').addClass("hide");
					$('.s_popup_box').removeClass("show");
					$('.s_popup_detailed').removeClass("show");
					
				}else{
					alert("删除失败！");
				}
			});
	  } 
	  return false; 
}
	function dialogue(id){
			//初始化数据，全部设置0
			top.customerId = id;
			top.actionId = 0;
			top.clueWeiboId = 0;
			top.writeOffId = 0;
//			$.post(path+"/api/customer_action/customerChatView",function(data){
				var d = top.dialog({
					fixed: true,
					zIndex: 10000,
					padding:0,
					width:1172,
					height:568,
					title:'沟通记录',
//					content:data,
					url:path+"/api/customer_action/customerChatView",
					cancelDisplay: false,
					cancel: function () {
						if(top.customerChatChange == 1){
							top.customerChatChange = 0;
						}
						top.customerId = 0;
						top.actionId = 0;
						top.clueWeiboId = 0;
						return true;
					}
				});
				d.showModal();
//			})
	}
	
function findByCustomerId(id){
	$.post(path+'/api/custome/findByCustomerId', {
		"customerID" : id,
	}, function(data) {
		data = JSON.parse(data);
		if(data.bcCustomer != 0){
			resetCustomer();
			$("#namea").val(isnull(data.bcCustomer.name));
			$("#phonea").val(isnull(data.bcCustomer.phone));
			$("#emaila").val(isnull(data.bcCustomer.email));
			$("#companya").val(isnull(data.bcCustomer.company));
			$("#joba").val(isnull(data.bcCustomer.job));
			$("#remarksa").val(isnull(data.bcCustomer.remarks));
			$("#gendera").val(isnull(data.bcCustomer.gender));
			$("#birthdaya").val(isnull(data.bcCustomer.birthday));
			$("#weiboa").val(isnull(data.bcCustomer.weibo));
			$("#qqa").val(isnull(data.bcCustomer.bak1));
			$("#wechata").val(isnull(data.bcCustomer.wechat));
			$("#addressa").val(isnull(data.bcCustomer.address));
			$("#citya").val(isnull(data.bcCustomer.city));
			$("#faxa").val(isnull(data.bcCustomer.fax));
			$("#taga").val(isnull(data.bcCustomer.tag));
			$("#customerID").val(id);
		}else{
			alert("编辑查询失败,未获取客户标识！")
		}
	});
	ShowArchitecture();
	$(".m_xpopups>.m_xconsum .title>span").text("修改客户");
	$('.m_xpopups , .m_xconsum').addClass('show');
	$('.m_xsubunit').removeClass('show');
}
//判断是否为空
function isnull(str){
	if(str == null ){
		return '';
	}else{
		return str;
	}
}
function resetCustomer(){
	$("#namea").val('');
	$("#phonea").val('');
	$("#emaila").val('');
	$("#companya").val('');
	$("#joba").val('');
	$("#remarksa").val('');
	$("#gendera").val('');
	$("#birthdaya").val('');
	$("#weiboa").val('');
	$("#qqa").val('');
	$("#wechata").val('');
	$("#addressa").val('');
	$("#citya").val('');
	$("#faxa").val('');
	$("#taga").val('');
	$("#customerID").val('');
}
